/* @flow */

export function resolveScopedSlots(
  fns: ScopedSlotsData, // see flow/vnode
  res

? : Object,
  // the following are added in 2.6
  hasDynamicKeys ? : boolean,
  contentHashKey ? : number
):
{
  [key
:
  string
]:
  Function, $stable
:
  boolean
}
{
  res = res || {$stable: !hasDynamicKeys}
  for (let i = 0; i < fns.length; i++) {
    const slot = fns[i]
    if (Array.isArray(slot)) {
      resolveScopedSlots(slot, res, hasDynamicKeys)
    } else if (slot) {
      // marker for reverse proxying v-slot without scope on this.$slots
      if (slot.proxy) {
        slot.fn.proxy = true
      }
      res[slot.key] = slot.fn
    }
  }
  if (contentHashKey) {
    (res: any)
  .
    $key = contentHashKey
  }
  return res
}
